class ROTAASSIST extends eui.Component implements  eui.UIComponent {
	ROTA:eui.RadioButton
	fistpos:egret.Point
	fistrotation:number
	public constructor() {
		super();
		this.fistpos=new egret.Point
	}

	protected partAdded(partName:string,instance:any):void
	{
		super.partAdded(partName,instance);
	}


	protected childrenCreated():void
	{
		super.childrenCreated();
	}
	public setup(x:number,y:number)
	{
		this.ROTA.x=x
		this.ROTA.y=y
		
		egret.MainContext.instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.onbegin,this)
		egret.MainContext.instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.onmove,this)
		egret.MainContext.instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.onbegin,this)
	}
	public closerota()
	{
		egret.MainContext.instance.stage.removeEventListener(egret.TouchEvent.TOUCH_BEGIN,this.onbegin,this)
		egret.MainContext.instance.stage.removeEventListener(egret.TouchEvent.TOUCH_MOVE,this.onmove,this)
		egret.MainContext.instance.stage.removeEventListener(egret.TouchEvent.TOUCH_END,this.onbegin,this)
	}
	private onbegin(e:egret.TouchEvent)
	{
       if(e.type==egret.TouchEvent.TOUCH_BEGIN)
	   {
	   let thisXY=new egret.Point(this.ROTA.x,this.ROTA.y)
       this.fistpos.x=e.stageX-thisXY.x
	   this.fistpos.y=e.stageY-thisXY.y
	   this.fistrotation=CMainEditor.editor.goal.rotation
	   }
	   else 
	   {
		   this.fistpos.x=0
		   this.fistpos.y=0
	   }
	   
	}
	private onmove(e:egret.TouchEvent)
	{
       let nowpos=new egret.Point
	   let thisXY=new egret.Point(this.ROTA.x,this.ROTA.y)
	   nowpos.x=e.stageX-thisXY.x
	   nowpos.y=e.stageY-thisXY.y
	   let dot=this.fistpos.x*nowpos.x+this.fistpos.y*nowpos.y
	   let fistposmo=Math.sqrt(this.fistpos.x*this.fistpos.x+this.fistpos.y*this.fistpos.y)
	   let nowposmo=Math.sqrt(nowpos.x*nowpos.x+nowpos.y*nowpos.y)
	   let cosA=dot/(fistposmo*nowposmo)
	 
	   let rotation=(180/Math.PI)*Math.acos(cosA)
	    if(nowpos.x<0&&nowpos.y>0)rotation+=360
		if(nowpos.x<0&&nowpos.y<0)rotation*=-1
		if(nowpos.x>0&&nowpos.y<0)
		{
			rotation*=-1;
            rotation-=90
		}
		console.log(nowpos.x,nowpos.y,rotation)
		//if(nowpos.x<0&&nowpos.y>0)rotation+=90
	    //if(rotation<0)rotation-=180;
	  // console.log(rotation)
	   let target=CMainEditor.editor.goal
	   target.rotation=rotation+this.fistrotation;

	}

	
}